package com.diaohw.module.websocket.selecter;

import org.springframework.cloud.commons.util.SpringFactoryImportSelector;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


@Order(Ordered.LOWEST_PRECEDENCE - 100)
public class AutoImportConfigurationSelector extends SpringFactoryImportSelector<EnableMyConfigurationSelector> {

    @Override
    public String[] selectImports(AnnotationMetadata metadata) {
        String[] imports = super.selectImports(metadata);
        List<String> importsList = new ArrayList<>(Arrays.asList(imports));

//        MsgProcessEnums[] types = types();
//        if (ArrayUtil.contains(types, MsgProcessEnums.HTTP)) {
//            importsList.add(HttpHandle.class.getName());
//        }
//        if (ArrayUtil.contains(types,MsgProcessEnums.RABBITMQ)){
//            importsList.add(RabbitMQHandle.class.getName());
//            importsList.add(RabbitMQConfig.class.getName());
//        }

        return importsList.toArray(new String[0]);
    }

    @Override
    protected boolean isEnabled() {
//        return getEnvironment().getProperty("spring.cloud.discovery.enabled", Boolean.class, Boolean.TRUE);
        return true;
    }

//    private MsgProcessEnums[] types() {
//        return getEnvironment().getProperty(CONFIG, MsgProcessEnums[].class, new MsgProcessEnums[0]);
//    }

    @Override
    protected boolean hasDefaultFactory() {
        return true;
    }
}
